import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
// import { OptionalAuthGuard } from '@wwjCommon/security/guards/optional-auth.guard';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request
import { AddressService } from '../../services/api/address.service';

/**
 * AddressController
 * 对应 PHP: Address Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('member')
@Controller('api/member')
@UseGuards(ApiCheckTokenGuard)
export class AddressController {
  constructor(private readonly addressService: AddressService) {}

  /**
   * lists
   * 路由: GET address
   * PHP路由: Route::get('address', 'member.Address/lists')
   */
  @Get('address')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'lists' })
  async lists(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: lists

      return await this.addressService.getList(data);
    } catch (error) {
      throw new BusinessException('lists操作失败', error);
    }
  }

  /**
   * info
   * 路由: GET address/:id
   * PHP路由: Route::get('address/:id', 'member.Address/info')
   */
  @Get('address/:id')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'info' })
  async info(@Param('id') id: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: info

      return await this.addressService.getInfo(id);
    } catch (error) {
      throw new BusinessException('info操作失败', error);
    }
  }

  /**
   * add
   * 路由: POST address
   * PHP路由: Route::post('address', 'member.Address/add')
   */
  @Post('address')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'add' })
  async add(@Body() data: AddDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: add

      return await this.addressService.add(data);
    } catch (error) {
      throw new BusinessException('add操作失败', error);
    }
  }

  /**
   * edit
   * 路由: PUT address/:id
   * PHP路由: Route::put('address/:id', 'member.Address/edit')
   */
  @Put('address/:id')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'edit' })
  async edit(
    @Param('id') id: string,
    @Body() data: EditDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: edit

      return await this.addressService.edit(id, data);
    } catch (error) {
      throw new BusinessException('edit操作失败', error);
    }
  }

  /**
   * del
   * 路由: DELETE address/:id
   * PHP路由: Route::delete('address/:id', 'member.Address/del')
   */
  @Delete('address/:id')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'del' })
  async del(@Param('id') id: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: del

      return await this.addressService.del(id);
    } catch (error) {
      throw new BusinessException('del操作失败', error);
    }
  }
}
